package view.transitions;

import java.awt.Graphics;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

public class CircleIn extends Animator {
	
	private BufferedImage	buffer;

	public CircleIn(BufferedImage from, BufferedImage to) {
		super(from, new BufferedImage(to.getWidth(), to.getHeight(), BufferedImage.TYPE_INT_ARGB));
		this.buffer = to;
	}

	@Override
	public void animate() {
		this.currentFrame++;
		
		float frameRatio = (float) this.currentFrame / Animator.MAX_FRAMES;
		
		int radius = (int) (Math.max(this.overlay.getWidth(), this.overlay.getHeight()));
		radius = (int)(radius - radius*frameRatio)/2;
		
		int width = this.overlay.getWidth();
		int height = this.overlay.getHeight();
		
		
		System.out.println("frameRation="+frameRatio+", radius = "+radius+", width = "+width+", height = "+height);
		
		Graphics g = this.overlay.getGraphics();
		Rectangle2D r2d = new Rectangle2D.Float(0, 0, width, height);
		g.setClip(r2d);
		g.drawImage(this.original, 0, 0, null);
		
		Ellipse2D circle = new Ellipse2D.Double(width/2-radius,height/2-radius, radius*2, radius*2);
		g.setClip(circle);
		
		
		
		//if(this.currentFrame %2 == 0)
				g.drawImage(this.buffer, 0, 0, null);
		//else
			//g.drawImage(this.original, 0, 0, null);
		
		g.dispose();
		
		
	}

}
